﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_DeleteSubsciption]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_DeleteSubsciption];
GO
CREATE PROCEDURE [dbo].[sproc_DeleteSubsciption] 
    @UserName nvarchar(300),
    @ClassIDs  nvarchar(300)
/*

=============================================================
功能:    删除订阅
参数:
    @StaffName nvarchar(300)    :    订阅人的姓名
    @ClassIDs  nvarchar(300)        :    订阅的项目ID集合

=============================================================

*/
As

Declare @StaffID int
Declare @sql nvarchar(2000)

SET @staffID =0
--得到订阅人的ID
SELECT @staffid = staff_id 
    FROM uds_staff 
    WHERE staff_name = @UserName
IF @staffid >0
Begin
    SET @sql = N'delete from uds_subscription where staff_id = ' +  cast(@staffid as nvarchar) + ' and classid in (' + @classids + ')'
    PRINT @sql
    EXEC (@sql)
END